from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-09 14:04:15.326974
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 09, Dec, 2021
Time: 14:04:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4273
Nobs: 500.000 HQIC: -47.8883
Log likelihood: 5751.27 FPE: 1.18337e-21
AIC: -48.1860 Det(Omega_mle): 9.90187e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.380734 0.080962 4.703 0.000
L1.Burgenland 0.094318 0.044227 2.133 0.033
L1.Kärnten -0.116012 0.022692 -5.112 0.000
L1.Niederösterreich 0.166978 0.091676 1.821 0.069
L1.Oberösterreich 0.129999 0.092775 1.401 0.161
L1.Salzburg 0.281936 0.047421 5.945 0.000
L1.Steiermark 0.015807 0.061249 0.258 0.796
L1.Tirol 0.106975 0.049471 2.162 0.031
L1.Vorarlberg -0.085533 0.043568 -1.963 0.050
L1.Wien 0.031817 0.083284 0.382 0.702
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.017993 0.179661 0.100 0.920
L1.Burgenland -0.051936 0.098145 -0.529 0.597
L1.Kärnten 0.036709 0.050356 0.729 0.466
L1.Niederösterreich -0.221357 0.203436 -1.088 0.277
L1.Oberösterreich 0.481854 0.205875 2.341 0.019
L1.Salzburg 0.312883 0.105231 2.973 0.003
L1.Steiermark 0.099069 0.135918 0.729 0.466
L1.Tirol 0.308014 0.109780 2.806 0.005
L1.Vorarlberg 0.008014 0.096681 0.083 0.934
L1.Wien 0.019366 0.184815 0.105 0.917
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220469 0.041339 5.333 0.000
L1.Burgenland 0.090407 0.022582 4.003 0.000
L1.Kärnten -0.004803 0.011586 -0.415 0.679
L1.Niederösterreich 0.221448 0.046809 4.731 0.000
L1.Oberösterreich 0.172718 0.047370 3.646 0.000
L1.Salzburg 0.036788 0.024213 1.519 0.129
L1.Steiermark 0.025766 0.031274 0.824 0.410
L1.Tirol 0.075761 0.025259 2.999 0.003
L1.Vorarlberg 0.055658 0.022245 2.502 0.012
L1.Wien 0.107166 0.042524 2.520 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159503 0.040203 3.967 0.000
L1.Burgenland 0.042921 0.021962 1.954 0.051
L1.Kärnten -0.012422 0.011268 -1.102 0.270
L1.Niederösterreich 0.148542 0.045523 3.263 0.001
L1.Oberösterreich 0.350779 0.046069 7.614 0.000
L1.Salzburg 0.100178 0.023548 4.254 0.000
L1.Steiermark 0.107620 0.030415 3.538 0.000
L1.Tirol 0.086238 0.024566 3.511 0.000
L1.Vorarlberg 0.053478 0.021634 2.472 0.013
L1.Wien -0.037389 0.041356 -0.904 0.366
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157996 0.077437 2.040 0.041
L1.Burgenland -0.041624 0.042302 -0.984 0.325
L1.Kärnten -0.036435 0.021704 -1.679 0.093
L1.Niederösterreich 0.126679 0.087684 1.445 0.149
L1.Oberösterreich 0.193808 0.088735 2.184 0.029
L1.Salzburg 0.255288 0.045356 5.629 0.000
L1.Steiermark 0.073040 0.058583 1.247 0.212
L1.Tirol 0.130486 0.047317 2.758 0.006
L1.Vorarlberg 0.104382 0.041671 2.505 0.012
L1.Wien 0.039610 0.079658 0.497 0.619
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079697 0.061358 1.299 0.194
L1.Burgenland 0.014234 0.033518 0.425 0.671
L1.Kärnten 0.051436 0.017197 2.991 0.003
L1.Niederösterreich 0.177395 0.069477 2.553 0.011
L1.Oberösterreich 0.341814 0.070310 4.861 0.000
L1.Salzburg 0.050356 0.035938 1.401 0.161
L1.Steiermark -0.006877 0.046419 -0.148 0.882
L1.Tirol 0.123184 0.037492 3.286 0.001
L1.Vorarlberg 0.058571 0.033018 1.774 0.076
L1.Wien 0.111876 0.063118 1.772 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169822 0.074451 2.281 0.023
L1.Burgenland 0.010922 0.040671 0.269 0.788
L1.Kärnten -0.060890 0.020867 -2.918 0.004
L1.Niederösterreich -0.112433 0.084304 -1.334 0.182
L1.Oberösterreich 0.234401 0.085314 2.747 0.006
L1.Salzburg 0.038142 0.043607 0.875 0.382
L1.Steiermark 0.263842 0.056324 4.684 0.000
L1.Tirol 0.489317 0.045493 10.756 0.000
L1.Vorarlberg 0.070927 0.040064 1.770 0.077
L1.Wien -0.101169 0.076587 -1.321 0.187
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138216 0.082279 1.680 0.093
L1.Burgenland -0.013401 0.044947 -0.298 0.766
L1.Kärnten 0.064097 0.023061 2.779 0.005
L1.Niederösterreich 0.171388 0.093167 1.840 0.066
L1.Oberösterreich -0.072690 0.094284 -0.771 0.441
L1.Salzburg 0.222177 0.048192 4.610 0.000
L1.Steiermark 0.134044 0.062246 2.153 0.031
L1.Tirol 0.049971 0.050275 0.994 0.320
L1.Vorarlberg 0.141859 0.044276 3.204 0.001
L1.Wien 0.168099 0.084639 1.986 0.047
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.454881 0.045458 10.007 0.000
L1.Burgenland -0.000833 0.024832 -0.034 0.973
L1.Kärnten -0.013305 0.012741 -1.044 0.296
L1.Niederösterreich 0.176650 0.051473 3.432 0.001
L1.Oberösterreich 0.269568 0.052090 5.175 0.000
L1.Salzburg 0.019135 0.026625 0.719 0.472
L1.Steiermark -0.013877 0.034390 -0.404 0.687
L1.Tirol 0.069498 0.027776 2.502 0.012
L1.Vorarlberg 0.056012 0.024462 2.290 0.022
L1.Wien -0.016039 0.046762 -0.343 0.732
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.026325 0.091079 0.154594 0.138452 0.063974 0.082096 0.015526 0.207469
Kärnten 0.026325 1.000000 -0.036804 0.127679 0.047963 0.072848 0.456501 -0.082183 0.094046
Niederösterreich 0.091079 -0.036804 1.000000 0.277657 0.098895 0.253324 0.051168 0.141251 0.244806
Oberösterreich 0.154594 0.127679 0.277657 1.000000 0.191906 0.285348 0.162168 0.124057 0.178670
Salzburg 0.138452 0.047963 0.098895 0.191906 1.000000 0.119701 0.061174 0.109588 0.063630
Steiermark 0.063974 0.072848 0.253324 0.285348 0.119701 1.000000 0.132358 0.087428 0.004806
Tirol 0.082096 0.456501 0.051168 0.162168 0.061174 0.132358 1.000000 0.063590 0.128381
Vorarlberg 0.015526 -0.082183 0.141251 0.124057 0.109588 0.087428 0.063590 1.000000 -0.011779
Wien 0.207469 0.094046 0.244806 0.178670 0.063630 0.004806 0.128381 -0.011779 1.000000